﻿//获取历史消息
var productlistpage = 0;
var productlistpage2 = 0;//热门
var productlistpagecount = 1;
var productlistpageSize = 6;
var productlistLiveId;
var isjz=0;//是否加载完成
var img = $("#progressImgage");
var mask = $("#maskOfProgressImage");
var rmtype=0;
var isjzrm=0;//热门是否加载完成

var producttpe=0;//0代表是product项目分页，1代表是product分页
function get_productlist(liveId) {
	productlistLiveId = liveId;
	if(productlistpage==0){
		$("#product").html(" ");
	//$("#prrlk").append(" <img  src='"+_path +"/images/shang.png' class='fanhui'   onclick='fanhuil()'>");
		 
	}
	producttpe=0;
	$
			.ajax({
				url : _path + "/productx/getproductxlist?id=2&rmtype="+rmtype+"&pageNo="
						+ productlistpage + "&pageSize=" + productlistpageSize,
				type : "get",
				dataType : "json",
				async : false,
				error : function(request) {
					alert("连接错误！");
				},	
				complete: function(XMLHttpRequest, textStatus) {
					 img = $("#progressImgage");
					 mask = $("#maskOfProgressImage");
					img.hide();//隐藏加载图片
					mask.hide(); //隐藏加载图片
					},
				success : function(jsonMap) {
			
					var list = jsonMap.datalist;
					var iTotalDisplayRecords = jsonMap.iTotalDisplayRecords;
			
					if (list.length > 0) {
						for (var i = 0; i < list.length; i++) {
							var data = list[i];
							var msgContent='';
						
							msgContent = "<li>"+
								 "<img src='"+data.imgUrl+ "'  alt=''>"+

								"	 <div class='dateil'>" +
							   "  <p>"+data.title+"</p>" +
								" <p>"+data.province+"</p>" +
								"    <p>  "+data.houses+"居/"+data.square+"平米/宜住"+data.yzrs+"人</p>"+
								"    <p></p>"+
								"     <p><s>原价：  "+
								" "+data.price+"</s>"+
								" 会员价："+
								" <span> "+
								" "+data.reduceprice+"</p>"+
								"</div>"+
								"    </li>";
						//	alert(	$("#apartList2").html())
						
					    	if(rmtype==0){
					    	     $('.swiperTab > li').eq(0).addClass('active');
							        tabs('.swiperTab > li','.swiper-container','active');
							        $("#apartList"+rmtype).append(msgContent);
							}else if(rmtype==1){
							    $('.swiperTab > li').eq(1).addClass('active');
						        tabs('.swiperTab > li','.swiper-container','active');
						        $("#apartList"+rmtype).append(msgContent);
							}
							
						
						}
					}
					// 分页
					var count = productlistpagecount * 6;
					if (count >= iTotalDisplayRecords) {
					
						if(rmtype==0){
							isjz=1;
						}else if(rmtype==1){
							isjzrm=1;
						}
					
						$("#productlistload"+rmtype)
								.html(
										"<div class='bl_more'><span id='spancolor'>已全部加载完</span></div>");
					}  
				}
			});
}
// 下一页
function productlistpageNext() {
	if(rmtype==0){
		productlistpagecount++;
		productlistpage = productlistpage + 6;
		get_productlist(productlistLiveId);
	}else if(rmtype==1){
		productlistpagecount++;
		productlistpage = productlistpage2 + 6;
		get_productlist(productlistLiveId);
	}

}






function get_producthide(id){
	
	productpage = 0;
		pageSize1 = 3;
	get_product(id);
}

$(function(){
$(window).scroll(function(){
	var scrollTop = $(window).scrollTop();
	var scrollHeight = document.body.scrollHeight;
	var windowHeight = document.documentElement.clientHeight;

	if (scrollTop + windowHeight >= scrollHeight) {
			//此处是滚动条到底部时候触发的事件，在这里写要加载的数据，或者是拉动滚动条的操作
		//	page = parseInt(page) + 1;//页数
		
			img.show().css({
				"position": "fixed",
				"top": "45%",
				"left": "40%",
				"margin-top": function () { return -1 * img.height() / 2; },
				"margin-left": function () { return -1 * img.width() / 2; }
			});//正在加载图标
					
				if($('.swiperTab > li').eq(0).attr("class")=='active'){
									rmtype=0;
									if(isjz!=1){
										
										productlistpageNext();
			
						}else{
							 $("#progressImgage").hide();//隐藏加载图片
							 $("#maskOfProgressImage").hide(); //隐藏加载图片
						}
				}else if($('.swiperTab > li').eq(1).attr("class")=='active'){
									rmtype=1;
									if(isjzrm!=1){
										productlistpageNext();
			
						}else{
							 $("#progressImgage").hide();//隐藏加载图片
							 $("#maskOfProgressImage").hide(); //隐藏加载图片
						}
				}
			
		
			
		
			
	}
});
});